package com.sutuijingling.utils;

import android.util.Log;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.commons.io.c;

public class b {
    static String a = "DS";
    static File b = new File("/data/local/tmp/ds_xposed.log");
    static PrintWriter c = null;
    static boolean d = false;
    private static SimpleDateFormat e = null;

    public static void a() {
        c.a(c);
    }

    public static void a(String str, Object... objArr) {
        b(String.format(str, objArr), new Object[0]);
    }

    public static void a(Throwable th, String str, Object... objArr) {
        th.printStackTrace();
        PrintStream printStream = System.err;
        String str2 = "DS[" + c().format(new Date()) + "] -> " + str;
        if (objArr == null || objArr.length <= 0) {
            System.err.println(str2);
            if (c != null) {
                c.println(str2);
                c.flush();
                return;
            }
            return;
        }
        String format = String.format(str2, objArr);
        System.err.println(str2);
        if (c != null) {
            c.println(format);
            c.flush();
        }
    }

    public static void b() {
        String absolutePath = b.getAbsolutePath();
        boolean d = a.d(absolutePath);
        System.out.println(" ds xposed log file exists??? :" + d);
        if (!d) {
            a.a(absolutePath, "");
        }
        a.b(a.c("/data/data/", b.class.getPackage().getName()), absolutePath);
        try {
            if (c == null) {
                c = new PrintWriter(b);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    public static void b(String str, Object... objArr) {
        String str2 = "[" + c().format(new Date()) + "] -> " + str;
        if (objArr == null || objArr.length <= 0) {
            System.out.println(str2);
            if (c != null) {
                c.println(str2);
                c.flush();
                return;
            }
            return;
        }
        str2 = String.format(str2, objArr);
        System.out.println(str2);
        if (c != null) {
            c.println(str2);
            c.flush();
        }
    }

    public static void b(Throwable th, String str, Object... objArr) {
        String str2 = "DS[" + c().format(new Date()) + "] -> " + str;
        if (objArr == null || objArr.length <= 0) {
            Log.e(a, str2, th);
            th.printStackTrace();
            return;
        }
        str2 = String.format(str2, objArr);
        System.out.println(str2);
        if (c != null) {
            c.println(str2);
            c.flush();
        }
    }

    protected static SimpleDateFormat c() {
        if (e != null) {
            return e;
        }
        e = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return e;
    }

    public static void c(String str, Object... objArr) {
        String str2 = "[" + c().format(new Date()) + "] -> " + str;
        if (objArr == null || objArr.length <= 0) {
            System.out.println(str2);
            if (c != null) {
                c.println(str2);
                c.flush();
                return;
            }
            return;
        }
        str2 = String.format(str2, objArr);
        System.out.println(str2);
        if (c != null) {
            c.println(str2);
            c.flush();
        }
    }
}
